import os
import time
from multiprocessing import Process


# def func():
#     for i in range(10):
#         time.sleep(1)
#         print(f"Hello,子进程PID={os.getpid()}")

def mydaemon():
    while True:
        print("daemon is alive!")
        time.sleep(1)


if __name__ == "__main__":
    # print(f"主进程PID={os.getpid()}")
    # process = Process(target=func)
    # process.start()
    # time.sleep(15)
    # print("主进程代码运行结束。")
    p = Process(target=mydaemon)
    p.daemon = True  # 设置当前子进程为守护进程，必须写在start()方法之前
    p.start()
    time.sleep(5)